package com.irdstudio.efp.flow.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.efp.flow.service.dao.BizFlowTaskParamDao;
import com.irdstudio.efp.flow.service.domain.BizFlowTaskParam;
import com.irdstudio.efp.flow.service.facade.BizFlowTaskParamService;
import com.irdstudio.efp.flow.service.vo.BizFlowTaskParamVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 业务任务参数				<p>
 * @author fuzm
 * @date 2018-05-12
 */
@Service("bizFlowTaskParamService")
public class BizFlowTaskParamServiceImpl implements BizFlowTaskParamService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(BizFlowTaskParamServiceImpl.class);

	@Autowired
	private BizFlowTaskParamDao bizFlowTaskParamDao;
	
	/**
	 * 新增操作
	 */
	public int insertBizFlowTaskParam(BizFlowTaskParamVO inBizFlowTaskParamVo) {
		logger.debug("当前新增数据为:"+ inBizFlowTaskParamVo.toString());
		int num = 0;
		try {
			BizFlowTaskParam bizFlowTaskParam = new BizFlowTaskParam();
			beanCopy(inBizFlowTaskParamVo, bizFlowTaskParam);
			num = bizFlowTaskParamDao.insertBizFlowTaskParam(bizFlowTaskParam);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(BizFlowTaskParamVO inBizFlowTaskParamVo) {
		logger.debug("当前删除数据条件为:"+ inBizFlowTaskParamVo);
		int num = 0;
		try {
			BizFlowTaskParam bizFlowTaskParam = new BizFlowTaskParam();
			beanCopy(inBizFlowTaskParamVo, bizFlowTaskParam);
			num = bizFlowTaskParamDao.deleteByPk(bizFlowTaskParam);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inBizFlowTaskParamVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(BizFlowTaskParamVO inBizFlowTaskParamVo) {
		logger.debug("当前修改数据为:"+ inBizFlowTaskParamVo.toString());
		int num = 0;
		try {
			BizFlowTaskParam bizFlowTaskParam = new BizFlowTaskParam();
			beanCopy(inBizFlowTaskParamVo, bizFlowTaskParam);
			num = bizFlowTaskParamDao.updateByPk(bizFlowTaskParam);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inBizFlowTaskParamVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public BizFlowTaskParamVO queryByPk(BizFlowTaskParamVO inBizFlowTaskParamVo) {
		
		logger.debug("当前查询参数信息为:"+ inBizFlowTaskParamVo);
		try {
			BizFlowTaskParam queryBizFlowTaskParam = new BizFlowTaskParam();
			beanCopy(inBizFlowTaskParamVo, queryBizFlowTaskParam);
			BizFlowTaskParam queryRslBizFlowTaskParam = bizFlowTaskParamDao.queryByPk(queryBizFlowTaskParam);
			if (Objects.nonNull(queryRslBizFlowTaskParam)) {
				BizFlowTaskParamVO outBizFlowTaskParamVo = beanCopy(queryRslBizFlowTaskParam, new BizFlowTaskParamVO());
				logger.debug("当前查询结果为:"+ outBizFlowTaskParamVo.toString());
				return outBizFlowTaskParamVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BizFlowTaskParamVO> queryAllOwner(BizFlowTaskParamVO bizFlowTaskParamVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<BizFlowTaskParamVO> list = null;
		try {
			List<BizFlowTaskParam> bizFlowTaskParams = bizFlowTaskParamDao.queryAllOwnerByPage(bizFlowTaskParamVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ bizFlowTaskParams.size());
			pageSet(bizFlowTaskParams, bizFlowTaskParamVo);
			list = (List<BizFlowTaskParamVO>) beansCopy(bizFlowTaskParams, BizFlowTaskParamVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BizFlowTaskParamVO> queryAllCurrOrg(BizFlowTaskParamVO bizFlowTaskParamVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<BizFlowTaskParam> bizFlowTaskParams = bizFlowTaskParamDao.queryAllCurrOrgByPage(bizFlowTaskParamVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+bizFlowTaskParams.size());
		List<BizFlowTaskParamVO> list = null;
		try {
			pageSet(bizFlowTaskParams, bizFlowTaskParamVo);
			list = (List<BizFlowTaskParamVO>) beansCopy(bizFlowTaskParams, BizFlowTaskParamVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BizFlowTaskParamVO> queryAllCurrDownOrg(BizFlowTaskParamVO bizFlowTaskParamVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<BizFlowTaskParam> bizFlowTaskParams = bizFlowTaskParamDao.queryAllCurrDownOrgByPage(bizFlowTaskParamVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ bizFlowTaskParams.size());
		List<BizFlowTaskParamVO> list = null;
		try {
			pageSet(bizFlowTaskParams, bizFlowTaskParamVo);
			list = (List<BizFlowTaskParamVO>) beansCopy(bizFlowTaskParams, BizFlowTaskParamVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	/**
	 * 根据任务编号查询
	 */
	public List<BizFlowTaskParamVO> queryTaskParamsByTaskId(String taskId) {
		logger.debug("根据任务编号："+ taskId +"查询对应参数信息开始......");
		List<BizFlowTaskParamVO> list = null;
		try {
			List<BizFlowTaskParam> bizFlowTaskParams = bizFlowTaskParamDao.queryTaskParamsByTaskId(taskId);
			list = (List<BizFlowTaskParamVO>) beansCopy(bizFlowTaskParams, BizFlowTaskParamVO.class);
			logger.debug("根据任务编号："+ taskId +"查询对应参数信息结束!");
		} catch (Exception e) {
			logger.error("根据任务编号："+ taskId +"查询对应参数信息出现异常!", e);
		}
		
		return list;
	}
}
